package com.xugui.learn.alibaba.tools;

import org.springframework.ai.chat.model.ToolContext;
import org.springframework.ai.tool.annotation.ToolParam;

import java.util.function.BiFunction;

/**
 * 用户位置工具 - 使用上下文
 */
public class UserLocationTool implements BiFunction<String, ToolContext, String> {
    @Override
    public String apply(
            @ToolParam(description = "User query") String query,
            ToolContext toolContext) {
        // 从上下文中获取用户信息  ToolContext
        String userId = (String) toolContext.getContext().get("user_id");
        return "1".equals(userId) ? "Florida" : "San Francisco";
    }
}
